package com.fbd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fbd.common.BaseContext;
import com.fbd.common.R;
import com.fbd.dto.DishDto;
import com.fbd.entity.Dish;
import com.fbd.entity.Orders;
import com.fbd.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R<String> save(@RequestBody Orders orders){
        ordersService.submit(orders);
        return R.success("购买成功");
    }
    //订单数据的分页查询
    @GetMapping("/userPage")
    public R<Page> page(int page,int pageSize){
        //构造分页构造器
        Page<Orders> pageInfo = new Page<>(page,pageSize);
        //1、获取用户id
        Long currentId = BaseContext.getCurrentId();
        //构造条件构造器
        LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Orders::getUserId,currentId);
        ordersService.page(pageInfo, wrapper);
        return R.success(pageInfo);
    }
}
